package com.tj.jinzao.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.tj.jinzao.R;
import com.tj.jinzao.base.BaseListAdapter;
import com.tj.jinzao.common.Constant;
import com.tj.jinzao.model.Goods;

import java.util.concurrent.CopyOnWriteArrayList;


/**
 * 商品 Adapter
 * Created by wjy on 2019/1/10.
 */
public class GoodsListItemAdapter extends BaseListAdapter<Goods, GoodsListItemAdapter.ViewHolder> {

    private int mItemWidth;

    public GoodsListItemAdapter(Context context, CopyOnWriteArrayList data, int itemWidth) {
        super(context, data);
        this.mItemWidth = itemWidth;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_goods_list, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Goods goods = mData.get(position);
        holder.name.setText(goods.getTitle());
        Glide.with(mContext).load(Constant.IMAGE_PREFIX + goods.getImgurl()).into(holder.goods);
        holder.score.setText(goods.getScore() + "积分");
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView goods;
        TextView name, score, status;

        public ViewHolder(View itemView) {
            super(itemView);
            goods = itemView.findViewById(R.id.iv_goods);
            ViewGroup.LayoutParams layoutParams = goods.getLayoutParams();
            layoutParams.width = mItemWidth;
            layoutParams.height = mItemWidth * 134 / 160;
            goods.setLayoutParams(layoutParams);
            name = itemView.findViewById(R.id.tv_name);
//            status = itemView.findViewById(R.id.tv_status);
            score = itemView.findViewById(R.id.tv_score);
        }
    }


}
